package myJs.detailInfo

import japgolly.scalajs.react.ScalaFnComponent
import japgolly.scalajs.react.vdom.all._
import myJs.Implicits._
import myJs.tool.Tool
import shared.pojo.Browse._

/** Created by yz on 28/11/2023
  */
object AssemblyGenomeCp {

  case class Props(basicData: AssemblyInfo)

  val Component = ScalaFnComponent[Props] { props =>

    val basicData = props.basicData

    object FTool {}

    if (basicData.genomeAnnoData.obj.nonEmpty) {
      div(
        h4(id:="genomeInfo","Genome-Annotation-Data"),
        div(
          className := "table-responsive",
          marginTop := 20.px,
          table(
            id := "genomeTable",
            className := "table table-striped table-hover table-bordered",
            tableLayout.fixed,
            wordWrap.breakWord,
            tbody(
              basicData.genomeAnnoData.obj.value.toList.toVdomArray { case (header, uV) =>
                val v = uV.str
                val trueV = if (v.isDouble) {
                  if (v.isInt) {
                    v
                  } else {
                    v.toDouble.toFixed(Tool.decDigits)
                  }
                } else v
                val finalV = header match {
                  case _ => span(trueV)
                }
                tr(
                  key := s"${header}",
                  th(header),
                  td(finalV)
                )
              }
            )
          )
        )
      )
    } else {
      EmptyVdom
    }

  }

  def apply(basicData: AssemblyInfo) = {
    Component(Props(basicData))
  }

}
